// ajax({
//     url:"",
//     success:(res)=>{},
//     error:(res)=>{},
//     data:{},
//     type:"get"
// })

function ajax({url,data,success,error,type}){
    type = type || "get";
    data = data || {};
    let str = "";
    for(let i in data){
        str += `${i}=${data[i]}&`;
    }
    str = str.slice(0,str.length-1);
    if(type === "get"){
        var d = new Date();
        url = url + "?" + str + "&__qft="+d.getTime();
    }
    let xhr = new XMLHttpRequest();
    xhr.open(type, url, true);
    if(type === "get"){
        xhr.send();
    }else if(type === "post"){
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xhr.send(str);
    }
    xhr.onload = function(){
        if(xhr.status === 200){
            success(xhr.responseText);
        }else{
            error && error(xhr.status);
        }
    }
}